package com.soyotec.algorithm.compare;

import com.soyotec.algorithm.solution.ValueWrapSolution;

import java.util.List;

public class SoyotecOptComparator extends AbstractComparator {

    private ValueWrapSolution optimalSolution;
    private ValueWrapSolution optimalInfeasibleSolution;

    public SoyotecOptComparator(){

    }

    public SoyotecOptComparator(ValueWrapSolution optimalSolution,ValueWrapSolution optimalInfeasibleSolution){
        this.optimalSolution = optimalSolution;
        this.optimalInfeasibleSolution = optimalInfeasibleSolution;
    }

    /**
     * 从当前这一代中比较出最优和最优不可行解
     * @param solutionList
     */
    public void compareSolutionList(List<ValueWrapSolution> solutionList){
        for(int i = 0;i < solutionList.size();i++){
            ValueWrapSolution nowSolution = solutionList.get(i);
            boolean feasible = nowSolution.isFeasible();
            if(feasible){
                optimalSolution = compareSolution(optimalSolution,nowSolution);
            } else {
                optimalInfeasibleSolution = compareSolution(optimalInfeasibleSolution,nowSolution);
            }
        }
    }

    public void compareOptimalSolution(List<ValueWrapSolution> solutionList){
        for(int i = 0;i < solutionList.size();i++){
            ValueWrapSolution nowSolution = solutionList.get(i);
            boolean feasible = nowSolution.isFeasible();
            if(feasible){
                optimalSolution = compareSolution(optimalSolution,nowSolution);
            }
        }
    }

    public void compareOptimalInfeasibleSolution(List<ValueWrapSolution> solutionList){
        for(int i = 0;i < solutionList.size();i++){
            ValueWrapSolution nowSolution = solutionList.get(i);
            boolean feasible = nowSolution.isFeasible();
            if(!feasible){
                optimalInfeasibleSolution = compareSolution(optimalInfeasibleSolution,nowSolution);
            }
        }
    }

    public ValueWrapSolution getOptimalSolution() {
        return optimalSolution;
    }

    public ValueWrapSolution getOptimalInfeasibleSolution() {
        return optimalInfeasibleSolution;
    }
}
